<template>
    <div class="goods-list">

        <div class="goods-item" v-for="item in goodslist" :key='item.id' @click='goDetail(item.id)'>
            <img :src="item.img_url" alt="">
            <h1 class="title">{{ item.title }}</h1>
            <div class="info">
                <p class="price">
                    <span class='now'>￥{{ item.now_price }}</span>
                    <span class="old">￥{{ item.old_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩{{ item.quantity }}件</span>
                </p>
            </div>
        </div>

        <mt-button type='danger' size='large' plain @click="getmore(item.pageIndex)">加载更多</mt-button>
    </div>
</template>

<script>

import {  Toast } from "mint-ui"

export default {
    data(){
        return{
            pageindex: 1,
            goodslist: [
                {
                    id:37,
                    title:"【限时抢券立减】Apple/苹果 iPhone X 64G 全网通4G智能手机 苹果X 苹果10 iPhone10】",
                    img_url:require("../../images/goods1.gif"),
                    now_price: 899,
                    old_price: 999,
                    quantity: 60
                },
                {
                    id:38,
                    title:"蒙牛特仑苏纯牛奶250ml*16盒营养升级 专属牧场",
                    img_url:require("../../images/goods2.jpg"),
                    now_price: 68.9,
                    old_price: 99,
                    quantity: 60
                },
                {
                    id:39,
                    title:"三只松鼠 年货坚果大礼包1523g每日坚果礼盒零食组合混合装8袋装",
                    img_url:require("../../images/goods3.jpg"),
                    now_price: 108,
                    old_price: 128,
                    quantity: 60
                }
            ]
        };
    },
    created(){
        this.getgoodslist();
    },
    methods:{
        getgoodslist(){
            // this.$http.get(""+this.pageindex).then(result=>{
            //     if(result.body.status === 0){
            //         this.goodslist = this.goodslist.concat(result.body.message);
            //     }else{
            //          Toast('获取商品列表失败')
            //     }
            // })

            Toast('获取商品列表失败');
        },
        getmore(){
            this.pageIndex++;
            this.getgoodslist();
        },
        //编程式导航
        goDetail(id){
            this.$router.push({ name:"goodsinfo",params:{ id }})
        }
    }




}
</script>

<style lang="scss" scoped>
    .goods-list{
        display: flex;
        flex-wrap: wrap;
        padding:2px 7px;
        justify-content: space-between;

        .goods-item{
            padding: 2px;
            width: 49%;
            border: 1px solid #ccc;
            box-shadow:0 0 5px #ccc;
            margin:3px 0px;
            display:flex;
            flex-direction: column;
            justify-content: space-between;
            min-height: 290px;

            img{
                width: 100%;
            }
            
            .title{
                font-size: 12px;
            }

            .info{
                background-color: #eee;

                .price{
                    font-size: 15px;
                    .now{
                        color:red;
                        font-weight: bold;
                    }
 
                    .old{
                        margin-left: 10px;
                        font-size: 10px;
                        text-decoration: line-through;
                    }
                }

                .sell{
                    display: flex;
                    justify-content: space-between;
                    font-size: 12px;
                    margin-bottom: 0px;
                }
            }
            
        }
        .mint-button{
            font-size: 14px;
            height: 32px;
        }
    }
</style>

